<template>
	<view class="tabbar flex">
		<view class="tabbar_item flex_center" v-for="item in list" @tap="openPath(item)">
			<image class="tabbar_icon" :src="item.id==id?item.selectIcon:item.icon"></image>
			<text class="tabbar_text" :class="item.id==id?'active_text':''">{{item.text}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		name: "tabbar",
		props: ["id"],
		data() {
			return {
				list: [{
					id: 1,
					icon: require("../static/img/tabbar/home.png"),
					selectIcon: require("../static/img/tabbar/homeActive.png"),
					text: "首页",
					path: "/pages/home/home"
				}, {
					id: 2,
					icon: require("../static/img/tabbar/position.png"),
					selectIcon: require("../static/img/tabbar/positionActive.png"),
					text: "持仓",
					path: "/pages/position/index"
				}, {
					id: 3,
					icon: require("../static/img/tabbar/explore.png"),
					selectIcon: require("../static/img/tabbar/exploreActive.png"),
					text: "探索",
					path: "/pages/explore/index"
				}, {
					id: 4,
					icon: require("../static/img/tabbar/history.png"),
					selectIcon: require("../static/img/tabbar/historyActive.png"),
					text: "历史",
					path: "/pages/history/index"
				}, {
					id: 5,
					icon: require("../static/img/tabbar/user.png"),
					selectIcon: require("../static/img/tabbar/userActive.png"),
					text: "我的",
					path: "/pages/user/index"
				}]
			};
		},
		methods: {
			openPath(opt) {
				if (opt.id == this.id) return
				uni.switchTab({
					url: opt.path
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar {
		height: 100rpx;
		background-color: #f7f7fa;

		.tabbar_item {
			flex-direction: column;
			flex: 1;

			.tabbar_icon {
				width: 40rpx;
				height: 40rpx;
			}

			.tabbar_text {
				color: #3d3d3d;
				font-size: 20rpx;
				line-height: normal;
				margin-top: 10rpx;
			}

			.active_text {
				color: #0065ff;
			}
		}
	}
</style>